<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>购物车</title>
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/total.css" />
</head>
<body style="background: #f7f7fa;">

<div class="left-body">
    <div id="header">
        <div class="header">
            <h1 class="tit">购物车</h1>
            <!--<p class="goback">-->
                <!--<a class="return"  onclick="self.location=document.referrer;">返回</a>-->
                <!--&lt;!&ndash;<a class="close" href="">关闭</a>&ndash;&gt;-->
            <!--</p>-->
            <!--<p class="more"><a class="share" href=""></a></p>-->
        </div>

    </div>
    <form action="{:U('Order/detail')}" class="form form-horizontal" id="add-confirm" method="post">
    <div class="gwc-zong">
        <notempty name="res">
            <div class="gwc-a">
                <div class="gwc-a-top">
                    <input type="checkbox" class="inp-che" name="check_all"/><span class="gwc-span">元典</span>
                </div>

                <ul class="gwc-ul">
                    <volist name="res" id="res">
                        <li class="li">
                            <div class="gwc-ul-one">
                                <if condition="$res['expired'] eq 1">
                                    <span class="abate">失效</span>
                                    <else/>
                                    <input type="checkbox" class="inp-ches" value="{$res['price']}"
                                           onclick="sum_money(this)"/>
                                    <input type="hidden" class="check_status" name="check_status[]" value="-1">
                                </if>
                                <input type="hidden" class="just_do" value="{$res['price']}">
                            </div>
                            <a class="gwc-ul-a" href="{:U('Good/goodsdetail' ,array('id'=>$res['good_id']))}">
                                <img src="{$res['good_pic']}" class="gwc-s">
                            </a>
                            <div class="gwc-li-div goods_box">
                                <div class="gwc-li-div-left">

                                    <a href="{:U('Good/goodsdetail' ,array('id'=>$res['good_id']))}"><p class="gwc-lidiv-p" style="overflow: hidden;">{$res['good_name']}</p></a>
                                    <p class="spec_str">{$res['spec_str']}</p>
                                    <p class="gwc-lidiv-money">¥
                                            <span class="price">{$res['price']}元</span>
                                            <input class="dollar" type="hidden" value="{$res['price']}">
                                    </p>
                                </div>
                                <div class="gwc-li-div-right">
                                    <div class="gwc-show">
                                        <img src="{:C('__STATIC__')}{$theme}/Static/img/bj.jpg" class="bianji">
                                        <p class="gwc-numbers goods_num">
                                            <input type="hidden" class="status" name="status[]" value="{$res['status']}">
                                            <input type="hidden" class="good_id" name="good_ida[]" value="{$res['good_id']}">
                                            <input type="hidden" class="spec_strr" name="good_spec[]" value="{$res['spec_str']}">
                                            <span class="jian del" data-price="">-</span>
                                            <input type="number" class="jishu num" name="good_num[]" value="{$res['good_num']}" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                            <span class="jia add" data-price="">+</span>
                                        </p>
                                    </div>
                                    <div class="gwc-hide">
                                        <input type="hidden" id="cookie_id" name="good_aid[]" value="{$res['cart_id']}">
                                        <div class="gwc-hide-number">
                                            <!--<p>×<a>1</a></p>-->
                                        </div>
                                        <div class="gwc-hide-delete">
                                            <span>删除</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </volist>
                </ul>
            </div>
            <else/>
            <div class="no_data">
                <img src="{:C('__STATIC__')}{$theme}/Static/img/no_data.png" class="tip_img"/>
                <p class="tip_txt">您的购物车没有任何物品</p>
            </div>
        </notempty>
    </div>



    <!--底部固定-->
    <div class="gwc-nav-top">
        <!--<div class="gwc-nav-left">-->
        <!--<input type="checkbox" class="gwc-top-inp"/><span class="gwc-top-span">全选</span>-->
        <!--</div>-->
        <div class="gwc-nav-center">
            <p><span>合计：¥&nbsp;<a class="gwc-top-money" id="count_money">0.00元</a></span></p>
            <input type="hidden" id="count" name="count" value=""/>
        </div>
        <button class="gwc-nav-right" id="balance">结算</button>
    </div>
    </form>
    <div class="footer">
        <ul class="footer-tab">
            <li>
                <a href="{:U('Index/index', array('shop_id'=>session('url_shop_id')))}">
                    <i class="foot_bg"></i>
                    <span>首页</span>
                </a>
            </li>
            <li>
                <a href="{:U('Good/cate')}">
                    <i class="foot_bg1"></i>
                    <span>分类</span>
                </a>
            </li>
            <li>
                <a href="{:U('GoodShopcart/shopcart')}">
                    <i class="foot_bg2 foot-this"></i>
                    <span>购物车</span>
                </a>
            </li>
            <li>
                <a href="{:U('Setting/personal')}">
                    <i class="foot_bg3"></i>
                    <span>我的</span>
                </a>
            </li>
        </ul>
    </div>
</div>


<!--添加收货地址-->
<div class="new-address">
    <div id="headera">
        <div class="header">
            <h1 class="tit">请先添加地址</h1>
            <p class="goback">
                <a class="gobody">返回</a>
            </p>
        </div>
    </div>
    <div class="tjxdz-a">
        <div class="tjxdz-a1">
            <span>收货人：</span>
            <input type="text" id="s_user"/>
        </div>
        <div class="tjxdz-a1">
            <span>联系电话：</span>
            <input type="text" id="s_mobile" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
        </div>
        <div class="tjxdz-a1">
            <span>所在地区：</span>
            <span class="content-block">请选择</span>
            <div class="content-chose" data-toggle="distpicker">
                <select id="provice"></select>
                <select id="city"></select>
                <select id="area"></select>
            </div>
        </div>
        <div class="tjxdz-a1 tjxdz-a4">
            <textarea placeholder="请填写详细地址" id="s_area" style="padding: 0;"></textarea>
        </div>
        <div class="person-form"><span id="add_btn">添加</span></div>
    </div>
</div>

<!--rem-->
<script>
    function resize() {
        var clientWidth = document.documentElement.clientWidth;
        document.documentElement.style.fontSize = 100 * (clientWidth / 750) + 'px';
    }
    resize();
    window.addEventListener('resize', resize);
</script>

<script type="text/javascript" src="{:C('__STATIC__')}{$theme}/Static/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/op.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.data.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/main.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery.form.min.js"></script>
<!--编辑-删除-->
<script>
    $(function() {

        //点击删除区域外,删除按钮消失
        $(document).click(function(e){
            obj = $(e.target);
              if (!$(obj).is(".li *")) {
                $('.gwc-show').show();
                $('.gwc-hide').hide();
              }
        });
        
        $(".gobody").click(function () {
            $(".new-address").removeClass("left-address");
            $(".left-body").removeClass("left-html");
        });
        $(".content-block").click(function () {
            $(".content-block").hide();
            $(".content-chose").show();
        })

        //加入购物车
        $("#add_btn").click(function () {
            //拼接规格和规格的值
            var s_user = $("#s_user").val();
            var s_mobile = $("#s_mobile").val();
            var provice = $("#provice").val();
            var city = $("#city").val();
            var area = $("#area").val();
            var s_area = $("#s_area").val();
            if(!/^1[3|4|5|8]\d{9}$/.test(s_mobile)){
                layer.alert("手机号码有误，请重填");
                return false;
            }
            if(!s_user || !s_mobile || !provice || !city || !area || !s_area){
                layer.alert('信息填写不完整！', {icon: 2});
                return false;
            }
            $.ajax({
                type: 'post',
                url:"{:U('Setting/address_add')}",
                data: {
                    tel: s_mobile,
                    get_user: s_user,
                    addre:s_area,
                    provice: provice,
                    city: city,
                    area: area
                },
                success: function(msg) {
                    if(msg.status == "success") {
                        layer.msg('添加成功！', {icon: 1 ,time: 1000});
                        setTimeout(function(){
                            location.reload(true);
                        }, 1000);
                    }
                }
            });
        })

        $(".inp-che").click(function(){
            $sum_money = 0,$sum_money = 0;
            if($(this).is(':checked')){
                $che_len = $(".inp-ches").length;
                for($i = 0;$i < $che_len;$i ++){
                    $buy_price = accMul($(".inp-ches").eq($i).val() ,$(".inp-ches").eq($i).parents("li").find(".num").val());
                    $sum_money = accAdd($sum_money ,$buy_price);
                }
            }
            $("#count_money").text($sum_money+"元");
            $("#count").val($sum_money);
        });


        $('.num').change(function() {
            var num = parseInt($(this).val());
//            alert(num);return false;
            if(isNaN(num)){
                $(this).val(1);
            }
            $s_price = $(this).next("span").attr("data-price");
            $(this).parents(".goods_box").find(".price").val(accMul(num,$s_price));
            $(this).parents("li").find(".just_do").val(accMul( num ,$s_price));
            sum_money();
        });
        $('.add').click(function() {
            var num = parseInt($(this).prev().val());
            num += 1;
            $(this).prev().val(num);
            $s_price = $(this).attr("data-price");
            $(this).parents(".goods_box").find(".price").val(accMul( num ,$s_price));
            $(this).parents("li").find(".just_do").val(accMul( num ,$s_price));

            sum_money();
        });
        $('.del').click(function() {
            var num = parseInt($(this).next().val());
            num -= 1;
            if(num <= 1){
                num = 1;
            }
            $(this).next().val(num);
            $s_price = $(this).attr("data-price");
            $(this).parents(".goods_box").find(".dollar").val(accMul( num ,$s_price));
            $(this).parents("li").find(".just_do").val(accMul( num ,$s_price));

            sum_money();
        });

        $(".bianji").click(function () {
            $('.gwc-show').show();
            $('.gwc-hide').hide();
            $(this).parent().parent().find('.gwc-hide').show();
            $(this).parent().parent().find('.gwc-show').hide();
//            var cookie_id = $(this).parent().parent().find('.gwc-hide').find('#cookie_id').val();
        });

        $('.gwc-hide').click(function () {
            var _this = $(this);
            var cookie_id = _this.parent().parent().find('.gwc-hide').find('#cookie_id').val()
            $.ajax({
                url: "{:U('GoodShopcart/shopcart')}",
                type: 'post',
                data: {
                    cookie_id:cookie_id
                },
                success: function () {
                    location.reload(true);
//                        _this.parent().parent().parent().remove();
                }
            })
        });

        $(".gwc-li-div-left").click(function () {
            $('.gwc-show').show();
            $('.gwc-hide').hide();
        });


        $(".fl-cc dl a").click(function(){
            $(".fl-cc dl a").eq($(this).index()).addClass("navdown").siblings().removeClass("navdown");
        })

        $(".inp-che").click(function () {
//                    全选，如果有去掉
            if( $(".inp-che").hasClass('wdt') ){
                $(this).removeClass("wdt");
                $(".inp-ches").removeClass("wdt");
                $(".inp-ches").prop('checked',false);
                $(".inp-ches").siblings(".check_status").val(-1);
            }else{
//                        如果没有，全部加上
                $(this).addClass("wdt");
                $(".inp-ches").addClass("wdt");
                $(".inp-ches").prop('checked',true);
                $(".inp-ches").siblings(".check_status").val(1);

            }
        });

        $(".inp-ches").click(function () {
//                    单选，如果有，去掉
            if($(this).hasClass("wdt") ){
                $(this).removeClass("wdt");
//                        此时如果全选有，全选去掉
                if( $(".inp-che").hasClass("wdt") ){
                    $(".inp-che").removeClass("wdt");
                    $(this).removeClass("wdt");
                }
            }else{
//                        如果没有，加上
                $(this).addClass("wdt");
            }
            $all_len = $(".inp-ches").length;
//                    如果单选全部都有，加上全选
            if($(".inp-ches:checked").length == $all_len){
                $(".inp-che").addClass("wdt");
                $(".inp-che").prop("checked" ,true);

            }else{
//                        如果单选有一个没有，去掉全选
                $(".inp-che").removeClass("wdt");
                $(".inp-che").prop("checked" ,false);
            }
        })

        $(".inp-ches").click(function () {
            if($(this).prop("checked") == true){
                $(this).siblings(".check_status").val(1);
            }else{
                $(this).siblings(".check_status").val(-1);
            }
        });

        $("#balance").click(function ()
        {
            var self_address = "{$self_address}";
            if(self_address == "none"){
                $(".new-address").addClass("left-address");
                $(".left-body").addClass("left-html");
                return false;
            }
            if($(".inp-ches:checked").length == 0){
                layer.msg("您还没有选择宝贝哟",{icon:8});
                return false;
            }
            $("#add-confirm").submit();
        });
    });

    var count = 0;
    function sum_money()
    {
//        选中的框的长度
        $che_len = $(".inp-ches").length;
        $sum_money = 0;
        for($i = 0;$i < $che_len;$i ++){
            if($(".inp-ches:eq("+$i+")").prop("checked") == true){
                $buy_price = accMul($(".inp-ches").eq($i).val() ,$(".inp-ches").eq($i).parents("li").find(".num").val());
                $sum_money = accAdd($sum_money ,$buy_price);
            }
        }
        $("#count_money").text($sum_money+"元");
        $("#count").val($sum_money);
    }
</script>
</body>
</html>
